<?php
/**
 * 获取课堂打分的信息
 * User: yaosj
 * Date: 15-4-20
 * Time: 下午6:28
 */

class GetGradescore implements iController{

    public function output($queryArgs) {
        global $cmsdb;

        if (validateUser($queryArgs) !== 1 || empty($queryArgs['live_class_id'])) {
            return genOutput(1000);
        }

        if (!empty($queryArgs['is_open']) && $queryArgs['is_open'] === 'true') {
            $queryArgs['live_class_id'] = $cmsdb->getVar('SELECT `class_id` FROM `relationship_live_class_and_course` WHERE `course_id`=:cid LIMIT 1',
                array(':cid' => $queryArgs['live_class_id']));
        }

        $sql = 'SELECT c.lector_id, t.name, t.introduction FROM `data_live_class` AS c INNER JOIN `data_teacher` AS t
        ON c.lector_id=t.id AND c.id='.$queryArgs['live_class_id'];
        $lector = $cmsdb->getRow($sql);

        $sql = 'SELECT `grade_score` FROM `data_liveclass_grade` WHERE `user_id`=:user_id AND `class_id`=:class_id LIMIT 1';
        $score = $cmsdb->getVar($sql, array(':user_id' => $queryArgs['user_id'], ':class_id' => $queryArgs['live_class_id']));

        return genOutput(1, array(
            'lector' => array(
                'id' => intval($lector->lector_id),
                'name' => $lector->name,
                'introduction' => $lector->introduction
            ),
            'score' => empty($score) ? 0 : intval($score)
        ));
    }
}
